/**
 *
 */
package prefix.platform.loan;

/**
 * @author Soul
 * 
 */
public enum LoanGrade {
    AA(0.0200),

    A(0.0200),
    B(0.0400),
    C(0.0450),
    D(0.0500),
    E(0.0500),
    F(0.0500),
    G(0.0500), ;

    private final double m_originationFeeRate;

    LoanGrade(double originationFee) {
        this.m_originationFeeRate = originationFee;
    }

    /**
     * TODO : remove this method when in loans you need AA loan grade
     */
    public static LoanGrade[] valuesTemp() {
        // this method filter AA loan grade, it's only called by loans.jsp
        LoanGrade[] grades = values();
        LoanGrade[] temp = new LoanGrade[grades.length - 1];
        for (int i = 1; i < grades.length; i++)
            temp[i - 1] = grades[i];
        return temp;
    }

    // -----------------------------------------------------------------------------------------
    // -----------------------------------------------------------------------------------------
    // --------------- Enum grade methods

    public double gradeGetAPR() {
        double val = 0.0;
        int number = 0;
        for (LoanClass lc : LoanClass.values()) {
            if (this == lc.getGrade()) {
                val += lc.getApr();
                number++;
            }
        }
        if (number == 0)
            return 0;
        return val / number;
    }

}
